package com.joymart.carousel.rest;

import com.joymart.common.utils.SecurityUtils;
import com.joymart.dictionary.Dictionary;
import com.joymart.dictionary.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;

/**
 * 活动卡片维护
 * 类似轮播图， 但多了详情图url属性
 */
@RestController
public class ActivityCardController {

    @Autowired
    private DictionaryService dictionaryService;

    @GetMapping("/activityCard/items")
    public Object getDictionary(){
        Dictionary dict = dictionaryService.findByName("activity_card_items");
        return dict.getKeyValues();
    }

    /**
     * 维护字典项
     * @param
     * @return
     */
    @PutMapping("/admin/activityCard/items")
    public void maintainDictionary( @RequestBody LinkedHashMap<String, Dictionary.Value> items){
        SecurityUtils.requiresRestAuthority("ProductRelated");
        Dictionary dict = new Dictionary();
        dict.setName("activity_card_items");
        dict.setKeyValues(items);
        dictionaryService.maintainDictionary(dict);
    }

}
